$title Condition model

* -----------------------------------------------------------------------------------
* Small open economy with conditional declaration and definition.
* Laurent Cretegny, CoPS, Monash University, Australia, 2004.
* -----------------------------------------------------------------------------------

$if not exist condition.gdx $call gdxxrw condition.xls index=declare

sets
  o                 commodity and sector
  f                 primary factor;

alias (o,s);

parameters
  sam(*,*)          benchmark social accounting matrix
  supply(s)         supply of output [[sppl:s]]
  interm(o,s)       intermediate demand [[intr:o*s]]
  factor(f,s)       factor demand [[fctr:f*s]]
  demand(s)         demand for consumption [[dmnd:s]]
  govdem(s)         government demand [[gvdm:s]]
  endow(f)          endowment [[endw:f]]
  export(s)         export (at fob price) [[expr:s]]
  import(s)         import (at cif price) [[impr:s]]
  bbop              balance of payments at the benchmark (surplus) [[bbop:]]
  etrn(s)           elasticity of transformation [[etrn:s]]
  esub(s)           elasticity of substitution [[esub:s]]
  esubc             elasticity of substitution for consumption [[esbc:]]
  esubm(s)          elasticity of substitution for import [[esbm:s]];

$gdxin condition
$load o f etrn esub esubc esubm sam
$gdxin

interm(o,s) = sam(o,s);
factor(f,s) = sam(f,s);
demand(s) = sam(s,"ra");
endow(f) = sam("ra",f);
export(s) = sam(s,"row");
import(s) = sam("row",s);
supply(s) = sum(o, interm(o,s)) + sum(f, factor(f,s)) - export(s);
bbop = sam("row","ra");

$if not exist condition.har $include gdxtohar

$ontext
$model:condition

$sectors:
  y(s)              ! production
  a(s)              ! aggregate supply
  e(s)$export(s)    ! export index
  m(s)$import(s)    ! import index
  u                 ! utility index

$commodities:
  pd(s)             ! domestic price of commodity
  pa(s)             ! price of commodity
  pf(f)             ! price of primary factor
  pe(s)$export(s)   ! price of export
  pm(s)$import(s)   ! price of import
  pu                ! price index for utility
  pfx               ! real exchange rate

$consumers:
  ra                ! representative agent income

$prod:y(s)          t:etrn(s)           id:0.5    va(id):esub(s)
  o:pd(s)                     q:supply(s)
  o:pe(s)                     q:export(s)
  i:pa(o)$sameas(o,s)         q:interm(o,s)
  i:pa(o)$(not sameas(o,s))   q:interm(o,s)       id:
  i:pf(f)                     q:factor(f,s)       va:

$prod:a(s)          s:esubm(s)
  o:pa(s)           q:(supply(s)+import(s))
  i:pd(s)           q:supply(s)
  i:pm(s)           q:import(s)

$prod:e(s)$export(s)
  o:pfx             q:export(s)
  i:pe(s)           q:export(s)

$prod:m(s)$import(s)
  o:pm(s)           q:import(s)
  i:pfx             q:import(s)

$prod:u             s:esubc
  o:pu              q:(sum(s, demand(s)))
  i:pa(s)           q:demand(s)

$demand:ra
  d:pu
  e:pf(f)           q:endow(f)
  e:pfx             q:-bbop

$report:
  v:rsupply(s)     o:pd(s)             prod:y(s)
  v:rdemand(s)     i:pa(s)             prod:u

$offtext
$sysinclude mpsgeset condition

* Benchmark replication

condition.iterlim = 0;
$include condition.gen
solve condition using mcp;
abort$(abs(condition.objval) gt 1e-7) "*** condition does not calibrate ! ***";
condition.iterlim = 1000;

* Fixation of a numeraire to allow comparison

pu.fx = pu.l;

* Counterfactual : trade balance requirement

bbop = 0;

$include condition.gen
solve condition using mcp;

* Results

parameters
  res_com           results by commodity in % change from basis
  res_agg           aggregate results in % change from basis; 

res_com("supply",s) = (rsupply.l(s)/supply(s) - 1) * 100;
res_com("export",s) = (e.l(s) - 1) * 100;
res_com("import",s) = (m.l(s) - 1) * 100;
res_com("demand",s) = (rdemand.l(s)/demand(s) - 1) * 100;
res_com("price",s) = (pa.l(s) - 1) * 100;

res_agg("u") = (u.l - 1) * 100;
res_agg("pu") = (pu.l - 1) * 100;
res_agg("pfx") = (pfx.l - 1) * 100;
res_agg("ra_inc") = (ra.l/(sum(s, demand(s))) - 1) * 100;

option decimals = 6;
display res_com, res_agg;
